package com.journey.org.ui.mine.account

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import com.journey.org.BR
import com.journey.org.R
import com.journey.org.databinding.FragmentMineAccountBinding
import com.journey.org.ui.custom.dialog.AccountDetailDialog
import com.mvvmhabit.org.base.BaseFragment

class AccountFragment : BaseFragment<FragmentMineAccountBinding, AccountViewModel>() {

    override fun initVariableId(): Int = BR.viewModel

    override fun initViewModel(): Class<AccountViewModel> = AccountViewModel::class.java

    override fun initContentView(
        inflater: LayoutInflater?,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): Int = R.layout.fragment_mine_account

    private var accountDetailDialog: AccountDetailDialog? = null

    override fun initData() {
        super.initData()
        mViewModel?.loadAccountList()
    }

    override fun initViewObservable() {
        super.initViewObservable()
        mViewModel?.onItemClickEvent?.observe(this, {
            if (accountDetailDialog == null) {
                accountDetailDialog = AccountDetailDialog(requireActivity())
            }
            accountDetailDialog?.showDialog()?.setEntity(it)
        })
    }


    override fun onDestroy() {
        super.onDestroy()
        accountDetailDialog?.onDestroy()
    }
}